/*
 * Copyright (c) 2014 pkzd/1.0, 颜文泽(robin)
 * All rights reserved.
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *     1 Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     2 Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef MC_PARAM_H
#define MC_PARAM_H

#define DRV_PARAM 	0x500
#define DRV_NUM		0x520
#define MEM_CNT		0x524		
#define IDE_CMD		0x528
#define IDE_CTRL	0x52c
#define IDE_SLV		0x530
#define IDE_TWO		0x534
#define IDE0_PARAM	0x600
#define IDE1_PARAM	0x800
	#define IDE_SER_OFF	0x14	
	#define IDE_LBA_OFF	0x62	
	#define IDE_SIZ_OFF	0x78	
#define MEM_ADDR	0x1000
	#define MEM_MAP	0x14
#define ELF_ADDR	0x1000		
#define LOAD_ADDR	0x2000		
#define KERN_ADDR	0x100000	
#define KERN_END	0x1000000	
#define USER_LMT	0x2000000

#define NIDE		0x02
#define IDE_ERR		0x01
#define IDE_IDX		0x02
#define IDE_CORR	0x04
#define IDE_DRQ		0x08
#define IDE_DSC		0x10
#define IDE_DF		0x20
#define IDE_DRDY	0x40
#define IDE_BUSY	0x80
#define IDE_MASK	0xc0
#define IDE_READ	0x20
#define IDE_WRITE	0x30
#define IDE_IDENTIFY	0xec
	#define IDE_SER_OFF	0x14
	#define IDE_LBA_OFF	0x62	
	#define IDE_SIZ_OFF	0x78

#define KEYBD_GATE0	0x60
#define KEYBD_GATE1	0x64

#define CR0_PE          0x00000001     	 
#define CR0_WP          0x00010000      
#define CR0_PG          0x80000000     	 
#define CR4_PSE         0x00000010	

#define PG_P	0x1
#define PG_W	0x2
#define PG_U	0x4
#define PG_A	0x20	
#define PG_M	0x40	
#define PG_PS	0x80
#define PG_COW	0x200	
#define PG_SWP  0x400	

#define PG_PTE_SHIFT	12
#define PG_PDE_SHIFT	22
#define PG_KERN_NUM	0x4
#define PG_TBL_NUM	0x400
#define PG_TBL_MASK	(0xfff)
#define PG_ADDR_MASK	(~0xfff)
#define PG_PDE(x)	(((x) >> PG_PDE_SHIFT) & 0x3ff)
#define PG_PTE(x)	(((x) >> PG_PTE_SHIFT) & 0x3ff)
#define PG_ADDR(x)	(((x) >> PG_PTE_SHIFT) & 0xfffff)

#define KPAGESIZ	0x400000
#define PAGESIZ         0x1000 
        #define PAGESIZ_OFF     12 
        #define PAGESIZ_MASK    ~(PAGESIZ - 1)
        #define RND_PAGE_SIZ(x)         (((x) & PAGESIZ_MASK) + PAGESIZ)
        #define OBT_PAGE_NUM(x)         ((((x) & PAGESIZ_MASK) >> PAGESIZ_OFF) + 1)

#define SECTORSIZ       0x200
        #define SECTORSIZ_OFF   9       
        #define SECTORSIZ_MASK  ~(SECTORSIZ - 1)
        #define OBT_SECTOR_NUM(x)       ((((x) & SECTORSIZ_MASK) >> SECTORSIZ_OFF) + (((x) & ~SECTORSIZ_MASK) ? 1 : 0))

#define BLKSIZ		0x400
	#define BLK_OFF	10
	#define BLK_MASK	~(BLKSIZ - 1)
	#define OBT_BLK_NUM(x)		((((x) & BLK_MASK) >> BLK_OFF) + (((x) & ~BLK_MASK) ? 1 : 0))

#define KERN_CSEL	0x08	
#define KERN_DSEL	0x10	
#define USER_CSEL	0x1b	
#define USER_DSEL	0x23	
#define TSS_SEL		0x28

#define FORK    1
#define EXECVE  2
#define EXIT    3
#define WAIT    4
#define GETPID  5
#define GETPPID 6
#define GETUID  7
#define GETEUID 8
#define GETGID  9
#define GETEGID 10
#define SETPGID 11
#define CREAT   12
#define OPEN    13
#define CLOSE   14
#define DUP     15
#define READ    16
#define WRITE   17
#define LSEEK   18
#define MKNOD   19
#define ACCESS  20
#define LINK    21
#define UNLINK  22
#define MKDIR   23
#define RMDIR   24
#define CHDIR   25
#define TIME    26
#define STAT	27
#define FSTAT	28
#define BRK	29
#define SYSCALL	0x80

#define PROCTIME	3	
#define SECTICKS	100     

#define STOP	0xffffffff

#define PMEM	0
#define PBIO	10	
#define PBUF	20	
#define PINOD	30	
#define PZERO	40	
#define PTTIN	50	
#define PTTOUT	60 
#define PPIPE	70	
#define PWAIT	80
#define PSLEEP	90	
#define PUSER	100	
#define	PIDLE	500	

#define VGA_ADDR	0xb8000
#define VGA_MEM_H	0x0c
#define VGA_MEM_L	0x0d
#define VGA_CUR_H	0x0e
#define VGA_CUR_L	0x0f
#define VGA_CMD		0x3d4
#define VGA_DAT		0x3d5
#define VGA_PER_CNT	2000
#define VGA_PER_SIZ	4000
#define VGA_TAB_SIZ	8
#define VGA_COL_SIZ	80
#define VGA_BLACK_WHITE	0x0700

#endif
